package org.zmhhxl.api.auth.factory;

import lombok.extern.slf4j.Slf4j;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.stereotype.Component;
import org.zmhhxl.api.auth.RemoteUserInfoService;
import org.zmhhxl.api.auth.domain.entity.UserInfo;
import org.zmhhxl.common.core.domain.Result;

import java.util.Optional;

/**
 * @Title: RemoteUserServiceFallbackFactory
 * @ProjectName: IntelliJ IDEA
 * @Description: TODO
 * @author: Administrator
 * @Date: 2024/10/11 0011下午 3:27
 */
@Component
@Slf4j
public class RemoteUserServiceFallbackFactory implements FallbackFactory<RemoteUserInfoService> {

   /**
    * Returns an instance of the fallback appropriate for the given cause.
    *
    * @param cause cause of an exception.
    * @return fallback
    */
   @Override public RemoteUserInfoService create(Throwable cause) {
      log.error("调用api-user服务失败:{}", cause.getMessage());
      return new RemoteUserInfoService(){

         @Override
         public org.zmhhxl.common.core.domain.Result<Optional<UserInfo>> findByUsername(String username) {
            return Result.fail("获取用户失败:" + cause.getMessage());
         }

         @Override
         public Optional<UserInfo> findById(Long userId) {
            return Optional.empty();
         }

//         @Override
//         public UserInfo save(UserInfo userInfo) {
//            return null;
//         }

         @Override public void recordLoginUser(UserInfo userInfo) {
            return ;
         }
      };
   }
}
